Reading permissions from one item to another

I am looking to read the permmisions from one item (in this case an attribute definition)and assign those permissions to another attribute. Has anyone a way of doing this? Probably involve converting a string to a Permission.
SystemAdmin - Tue Nov 03 12:31:00 EST 2009

Re: Reading permissions from one item to another
llandale - Tue Nov 03 14:29:10 EST 2009

You need to get the Access Records of Attr1, get the names and accesses, then apply them to Attr2. One of the 'nuances' is that there are two kinds of accesses for an attribute def: [1] access to the DEF (can the user re-define the attribute), and [2] access to the VALUES (can the user change the value of an object). The commands therefore have 'Def' or 'Val' suffixes to distinquish the two.

You need to know whether Attr1 is Inherited or Specific. If Inherited, set Attr2 Inherited. If Specific set Attr2 to Specific, then plow through the AccessRecs of the attr, get the name and the permission, then set that to Attr2.

I suppose you would erase the AccessRecs for Attr2 but without removing your own access! Perhaps then first plow through the AccessRecs of Attr2 and store them in a Skip list. When applying Attr1 access for a user/group, remove that User/group from Attr2's originals. When done, plow through the Skip List removing the residual old AccesRecs for Attr2.

I did not try the following code to change the accesses for DEF, but it will get you started:

//********************************
Permission    fPermisOf(AccessRec ar)
{             // Get the Permissions associated with the AccessRec.
 
        Permission      Permis  = none()
        if (null ar)    return(Permis)
        if (read(ar))           Permis = Permis | read
        if (modify(ar))         Permis = Permis | modify
        if (create(ar))         Permis = Permis | create
        if (delete(ar))         Permis = Permis | delete
        if (control(ar))        Permis = Permis | control
        return(Permis)
}     // end fPermisOf(ar)
 
 
Module mod = current
AttrDef ad1 = find(mod, "Attr1")
AttrDef ad2 = find(mod, "Attr2")
AccessRec   ar1, ar2
Permission  ps1
string      Name
 
bool   IsInherit1, IsInherit2
isAccessInheritedDef(mod, ar1, IsInherit1)
isAccessInheritedDef(mod, ar2, InInherit2)
 
if ( IsInherit1 and  IsInherit2) then return.  // Nothing to do
if ( IsInherit1 and !IsInherit2) then inheritedDef(mod, ad2); return  // set Attr2 Inherited.  Nothing else to do
if (!IsInherit1 and  IsInherit2) then specificDef(mod, ad2)  // Set Attr2 to specific.  Proceed.
    // At this point, Attr1 and Attr2 both have Specific access.  Make Attr2 access same as Attr1
 
Skip  skpAccess2 = createString() // Original accesses to Attr2.
                                  // KEY and DATA both 'string' User/Group name
       // Store Attr2's original Names
for ar2 in ad2 do      // For values, this is "for ar2 in values(ad2) do"
{  Name = username(ar2)
   put(skpAccess2, Name, Name)
}
 
      // Give Attr2 same access records as Attr1
 
for ar1 in ad1 do
{  Name = username(ar1)      // Name of this access
   ps1  = fPermisOf(ar1)     // Permissions for this access
 
   setDef(mod, ad2, ps1, Name)
   delete(skpAccess2, Name)   // Delete this name from the old 2 list; ignore not-there error
}
      // Delete residual Attr2 Accesses
for Name in skpAccess2 do
{  if (null Name)
   {  // this is the default 'Everyone Else' acesses.  Don't think its possible to get
      //   Here since Attr1 MUSt have a default access and it was removed from the skip
   }
   else unsetDef(mod, ad2, Name)
}
delete(skpAccess2)

 


But I suppose you want to protect the Values. Change 'Def' suffix to 'Val', and use the values(ad2) loop.

 

 

 

  • Louie

 

 

Re: Reading permissions from one item to another
SystemAdmin - Wed Nov 04 12:59:36 EST 2009

Many Thanks Louie, that got me sorted. Needed a few tweeks but the main problem was that the default permissions caused DOORS to crash, both when putting the returned null string in "Name" into the stream and using the same string in the setDef command. Easy to overcome though so I'm a happy bunny. Thanks again.

Re: Reading permissions from one item to another
llandale - Wed Nov 04 15:12:34 EST 2009

SystemAdmin - Wed Nov 04 12:59:36 EST 2009
Many Thanks Louie, that got me sorted. Needed a few tweeks but the main problem was that the default permissions caused DOORS to crash, both when putting the returned null string in "Name" into the stream and using the same string in the setDef command. Easy to overcome though so I'm a happy bunny. Thanks again.

Rat in the morning, Bunny in the afternoon? I can relate to that ... except for the Bunny part. lol

If you got something that worked, go ahead and post it.

  • Louie

Re: Reading permissions from one item to another
SystemAdmin - Fri Nov 06 07:04:14 EST 2009

llandale - Wed Nov 04 15:12:34 EST 2009
Rat in the morning, Bunny in the afternoon? I can relate to that ... except for the Bunny part. lol

If you got something that worked, go ahead and post it.

  • Louie

This works a treat :-

Permission fPermisOf(AccessRec ar)
{
// Get the Permissions associated with the AccessRec.

Permission Permis = none()
if (null ar) return(Permis)
if (read(ar)) Permis = Permis | read
if (modify(ar)) Permis = Permis | modify
if (create(ar)) Permis = Permis | create
if (delete(ar)) Permis = Permis | delete
if (control(ar)) Permis = Permis | control
return(Permis)
// end fPermisOf(ar)
}

void setAttributeAccessRights(AttrDef adS, AttrDef adT)
{

AccessRec arS, arT
Permission ps1
string Name

bool IsInheritS, IsInheritT

// For Attribute Definition :-

isAccessInheritedDef(StandardModule, adS, IsInheritS)

isAccessInheritedDef(TargetModule, adT, IsInheritT)

if ( IsInheritS and IsInheritT)
{
// Nothing to do
} else if ( IsInheritS and !IsInheritT)
{
inheritedDef(TargetModule, adT)
// set Attr2 Inherited. Nothing else to do
}else
{
if (!IsInheritS and IsInheritT) then specificDef(TargetModule, adT) // Set Attr2 to specific. Proceed.

// At this point, Attr1 and Attr2 both have Specific access. Make Attr2 access same as Attr1

unsetAllDef(TargetModule, adT) // Clear out existing access rights

// Give Attr2 same access records as Attr1

for arS in adS do
{
Name = username(arS) // Name of this access
ps1 = fPermisOf(arS) // Permissions for this access

if (!null Name)
{
setDef(TargetModule, adT, ps1, Name)
} else
{
setDef(TargetModule, adT, ps1, null)
}
}
}
}

Thanks for your help Louie

TheRat (Otherwise known as Pete)